//
//  DDAlertView.m
//  DongDongWedding
//
//  Created by 谢曦 on 16/9/12.
//  Copyright © 2016年 gl. All rights reserved.
//

#import "XXAlertView.h"
#import "MMPopupItem.h"
#import "UIColor+Hexadecimal.h"
#define BlackColor  [UIColor blackColor]
#define GrayColor [UIColor colorWithHex:@"#949494"];
@implementation XXAlertView

+(XXAlertView *)alertViewWithTitle:(NSString *)title detail:(NSString *)detail redButtonTitle:(NSString *)redString otherbuttonTitle:(NSArray *)buttonStrings
{
      
    NSMutableArray *itemsArr=[NSMutableArray array];
        [buttonStrings enumerateObjectsUsingBlock:^(NSString *btnStr, NSUInteger idx, BOOL * _Nonnull stop) {
        MMPopupItem *otherItem = [MMPopupItem new];
        otherItem.title = btnStr;
           [itemsArr addObject:otherItem];
     
    }];
    if (title.length!=0) {
        MMPopupItem *itemRed = [MMPopupItem new];
        itemRed.title = redString;
        itemRed.highlight=YES;
         [itemsArr addObject:itemRed];
    }
    
  
    //config alert
    [MMAlertViewConfig globalConfig].titleColor=BlackColor;
    [MMAlertViewConfig globalConfig].detailColor=GrayColor;
    [MMAlertViewConfig globalConfig].itemNormalColor=ThemeBlackColor;
    [MMAlertViewConfig globalConfig].itemHighlightColor=[UIColor redColor];
    [MMAlertViewConfig globalConfig].titleFontSize=15;
    [MMAlertViewConfig globalConfig].detailFontSize=13;
    [MMAlertViewConfig globalConfig].buttonFontSize=14;
//    [MMAlertViewConfig globalConfig].splitColor=[UIColor clearColor];

    XXAlertView *alert = [[XXAlertView alloc] initWithTitle:title detail:detail items:itemsArr];
   
       [itemsArr enumerateObjectsUsingBlock:^(MMPopupItem *item, NSUInteger idx, BOOL * _Nonnull stop) {
        if (item.highlight==YES) {

            item.handler=^(NSInteger index){
                if (alert.alertViewRedButtonClickBlock) {
                alert.alertViewRedButtonClickBlock();
                                }
            };
          }
        else
        {
      item.handler=^(NSInteger index){
                if (alert.alertViewOtherButtonClickBlock) {
                    alert.alertViewOtherButtonClickBlock(index);
                }
            };

        }
        
    }];
    
    
    return alert;

}


-(void)showAlertView
{
    [self show];

}



@end




@implementation XXSheetView

+(XXSheetView *)sheetViewWithTitle:(NSString *)title redButtonTitle:(NSString *)redString otherbuttonTitle:(NSArray *)buttonStrings
{
    NSMutableArray *itemsArr=[NSMutableArray array];
    
   
    [buttonStrings enumerateObjectsUsingBlock:^(NSString *btnStr, NSUInteger idx, BOOL * _Nonnull stop) {
        MMPopupItem *otherItem = [MMPopupItem new];
        otherItem.title = btnStr;
        [itemsArr addObject:otherItem];
        
    }];
    if(redString.length>0)
    {
    MMPopupItem *itemRed = [MMPopupItem new];
    itemRed.title = redString;
    itemRed.highlight=YES;
    [itemsArr addObject:itemRed];
    }
    
    //config alert
    [MMSheetViewConfig globalConfig].titleColor=GrayColor;
    [MMSheetViewConfig globalConfig].itemNormalColor=BlackColor;;
    [MMSheetViewConfig globalConfig].itemHighlightColor=[UIColor redColor];
    [MMSheetViewConfig globalConfig].titleFontSize=13;
    [MMSheetViewConfig globalConfig].buttonFontSize=17;
    
    XXSheetView *sheet = [[XXSheetView alloc] initWithTitle:title items:itemsArr];
    
    
    
    
    [itemsArr enumerateObjectsUsingBlock:^(MMPopupItem *item, NSUInteger idx, BOOL * _Nonnull stop) {
        if (item.highlight==YES) {
            
            item.handler=^(NSInteger index){
                if (sheet.sheetViewRedButtonClickBlock) {
                    sheet.sheetViewRedButtonClickBlock();
                }
            };
            
            
            
        }
        else
        {
            
            
            item.handler=^(NSInteger index){
                if (sheet.sheetViewOtherButtonClickBlock) {
                    sheet.sheetViewOtherButtonClickBlock(index,item.title);
                    
                }
            };
            
        }
        
    }];
    
    
    return sheet;



}
-(void)setDefaultTextCancel:(NSString *)defaultTextCancel{
    _defaultTextCancel=defaultTextCancel;
    [MMSheetViewConfig globalConfig].defaultTextCancel=defaultTextCancel;
}
-(void)showSheetView
{
    [self show];

}
@end
